/**
 * Created by Administrator on 2016/3/2.
 * 兑换券结算页面
 */
gpNamespace.DhqJsLayer = cc.Layer.extend({
	isApplying:false,
	levalTicketArray:[2000,5000,10000,100000],
	
	ctor: function () {
		this._super();


		this.init();
	},

	init: function () {
		cc.spriteFrameCache.addSpriteFrames(gpNamespace.awardRes.Award_plist);

		cc.log("进入init界面===============================");

		//黄色全屏背景图层
		var backgroundBg = new cc.Sprite(gpNamespace.award.Award_bigBg);
		backgroundBg.attr({
			x: cc.winSize.width/2 ,
			y: cc.winSize.height/2 ,
			anchorX: 0.5,
			anchorY: 0.5
		});
		this.addChild(backgroundBg);

		//半透明背景图层
		var background = new cc.Sprite(gpNamespace.award.Award_bg);
		background.attr({
			x: cc.winSize.width/2 ,
			y: 115 ,
			anchorX: 0.5,
			anchorY: 0
		});
		this.addChild(background);
		
		var reward = new cc.Sprite("#cdd_jz_00"+(gpNamespace.CurrentDhqLevel+1)+"u.png");
		reward.attr({
			x: 530 ,
			y: 316 ,
			anchorX: 0,
			anchorY: 0
		});
		this.addChild(reward);
		
		var leaveBt = new cc.MenuItemImage(gpNamespace.award.Award_leave,gpNamespace.award.Award_leave,this.leaveCallback,this);
		leaveBt.attr({
			x:330,
			y:12,
			anchorX: 0,
			anchorY: 0,
		})
		var againBt = new cc.MenuItemImage(gpNamespace.award.Award_again,gpNamespace.award.Award_again,this.againCallback,this);
		againBt.attr({
			x:700,
			y:12,
			anchorX: 0,
			anchorY: 0,
		})
		this.againBt = againBt;
		var menu = new cc.Menu(leaveBt,againBt);
		menu.attr({
			x: 0,
			y: 0,
			anchorX: 0,
			anchorY: 0,
		})
		this.addChild(menu);
		
		var currentDate = new Date();
		var year = new tyNamespace.NumLayer(currentDate.getFullYear(),14,65,"sz_cdd_js_"); 
		year.attr({
			x:870,
			y:200
		})
		this.addChild(year);
		var point1 = new cc.LabelTTF(".",gpNamespace.DEFAULTFONT,25);
		point1.setFontFillColor(cc.color(255,255,0,255));
		point1.attr({
			x:year.getPositionX()+35,
			y:year.getPositionY()
		})
		this.addChild(point1);
		
		var month = new tyNamespace.NumLayer(currentDate.getMonth()+1,14,65,"sz_cdd_js_"); 
		month.attr({
			x:year.getPositionX()+45,
			y:year.getPositionY()
		})
		this.addChild(month);
		var point2 = new cc.LabelTTF(".",gpNamespace.DEFAULTFONT,25);
		point2.setFontFillColor(cc.color(255,255,0,255));
		point2.attr({
			x:month.getPositionX()+15,
			y:month.getPositionY()
		})
		this.addChild(point2);
		var day = new tyNamespace.NumLayer(currentDate.getDate(),14,65,"sz_cdd_js_"); 
		day.attr({
			x:month.getPositionX()+30,
			y:year.getPositionY()
		})
		this.addChild(day);
		cc.log(currentDate.getFullYear()+"."+(currentDate.getMonth()+1)+"."+currentDate.getDate());
	},
	leaveCallback:function(){
		gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonBack, false);

		var cddNet = gpNamespace.NetManager.getInstance();

		cddNet.removeMyListeners();

		gpNamespace.NetManager.instance = null;

//		xinyou.netManager.leaveTable();
//		xinyou.netManager.leaveRoom();

		userInfo.gold = userInfo.gold + this.levalTicketArray[gpNamespace.CurrentDhqLevel-1];
		cc.director.runScene(new cc.TransitionFade(0.5, new gpNamespace.GpMainScene()));
	},
	againCallback:function(sender){
		gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);
		tyNamespace.setMenuEnable(sender,1);
		if(userInfo.gold < this.levalTicketArray[gpNamespace.CurrentDhqLevel-1]){
			tyNamespace.warningJumper(1, tyNamespace.WarningSectencesIndex.NoGold,function(){
				cc.director.runScene(new cc.TransitionFade(0.5, new gpNamespace.GpMainScene()));
			});
			return;
		}
		this.isApplying = true;

		var dzmjNet = gpNamespace.NetManager.getInstance();
		dzmjNet.baoMingLayer = this;
		this.againBt.setEnabled(false);
		this.againBt.setOpacity(200);

		//等待中
		var armature = new ccs.Armature("loading_001u");
		armature.getAnimation().playWithIndex(0);
		armature.getAnimation().setSpeedScale(1);
		armature.setScale(1);
		armature.setAnchorPoint(0.5, 0.5);
		armature.setPosition(640, 360);
		armature.setTag(11);
		this.addChild(armature,10);

		var cddNet = gpNamespace.NetManager.getInstance();
		cddNet.baoMingLayer = this;
		xinyou.netManager.inRoom(6, gpNamespace.CurrentDhqLevel+17, 1);
		userInfo.gold = userInfo.gold - this.levalTicketArray[gpNamespace.CurrentDhqLevel-1];
	}
});